<style>
    .companyFormPhotos{
        /* margin-left:140px; */
        line-height: 38px;
        float: left;
    }
    .companyFormPhotos img{
        cursor: pointer;
        height: 38px;
        width: auto;
        max-width: 200px;
    }
    .contractFileUrlCont{
        width: 100%;
        height: 400px;
    }
    .contractFileUrlCont>div{
        width: 100%;
        float: left;
        margin-right: 30px;
        padding-top: 10px;
        font-size: 16px;
        padding-left: 20px;
    }
    .contractFileUrlCont img{
        width: 100%;
        height: 100%;
        object-fit: contain;
    }
</style>
<!-- 正文开始 -->
<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-card-body">
            <!-- 头部操作栏 -->
            <div class="layui-form lay-header">
                <div class="toolbar">
                    <div class="layui-form-item lay-query-content">
                        <div class="lay-query-box">
                            <div class="query-lt">
                                <div class="layui-inline">
                                    <label class="layui-form-label w-auto">合同名称</label>
                                    <div class="layui-input-inline mr0">
                                        <input name="contractName" class="layui-input" type="text" placeholder="请输入合同名称" autocomplete="off"/>
                                    </div>
                                </div>
                                <div class="layui-inline">
                                    <label class="layui-form-label w-auto">所属企业</label>
                                    <div class="layui-input-inline mr0">
                                        <input name="warehouseCustomerName" class="layui-input" type="text" placeholder="请输入所属企业" autocomplete="off"/>
                                    </div>
                                </div>
                                <div class="layui-inline">
                                    <button class="layui-btn icon-btn color-green" lay-filter="formSubSearchLog" lay-submit layui-form-keyDownSearch="true">查询</button>
                                    <button class="layui-btn icon-btn color-white" lay-filter="resets" lay-submit>重置</button>
                                </div>
                            </div>
                            <div class="query-rt">

                            </div>
                        </div>
                    </div>
                </div>
<!--                <div class="lay-btn-rows">-->
<!--                    <div class="lay-btn-box">-->
<!--                        <div class="lay-btn-lt">-->
<!--                            <button id="warehouseContractBtnAdd" class="layui-btn icon-btn color-reseda">添加</button>-->
<!--                        </div>-->
<!--                        <div class="lay-btn-rt">-->
<!--                        </div>-->
<!--                    </div>-->
<!--                </div>-->
            </div>
            <!-- 表格 -->
            <table class="layui-table" id="warehouseContractTable" lay-filter="warehouseContractTable"></table>
        </div>
    </div>
</div>

<!-- 表格操作列 -->
<script type="text/html" id="warehouseContractTableBar">
    <a class="layui-btn layui-btn-warm layui-btn-xs" lay-event="info">查看</a>
<!--    <a class="layui-btn layui-btn-warm layui-btn-xs" lay-event="edit">修改</a>-->
<!--    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>-->
</script>

<!-- 表单弹窗 -->
<script type="text/html" id="warehouseContractForm">
    <form lay-filter="warehouseContractForm" class="layui-form model-form">
        <input name="id" type="hidden"/>
        <div class="layui-form-item">
            <label class="layui-form-label">所属客户</label>
            <div class="layui-input-block">
                <input type="hidden" id="customerName" name="customerName" />
                <select id="customerNameId" name="customerNameId" lay-filter="customerNameId"
                        lay-verify="required" required></select>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">合同类型</label>
            <div class="layui-input-block">
                <input type="text" id="type" name="type" value="1"  class="layui-input" disabled />
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">合同分类</label>
            <div class="layui-input-block">
                <select  id="contractCategoryId" name="contractCategoryId" lay-filter="contractCategoryId" lay-verify="required" lay-search required></select>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">关联托管订单</label>
            <div class="layui-input-block">
                <input type="text" id="orderCode" name="orderCode" placeholder="请选择关联托管订单"  lay-verify="required"  required class="layui-input"  />
                <!--                <select  id="orderCode" name="orderCode" lay-filter="orderCode" lay-verify="required" lay-search required></select>-->
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">合同备注号</label>
            <div class="layui-input-block">
                <input id="contractRemark" name="contractRemark" placeholder="请输入合同备注号" type="text" class="layui-input" autocomplete="off" />
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">合同金额</label>
            <div class="layui-input-block">
                <input id="contractPrice" name="contractPrice" placeholder="请输入合同金额" type="text" class="layui-input" autocomplete="off" />
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">合同名称</label>
            <div class="layui-input-block">
                <input id="contractName" name="contractName" disabled placeholder="请输入合同名称" type="text" class="layui-input" autocomplete="off"/>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">客户签约人</label>
            <div class="layui-input-block">
                <input  id="warehouseCustomerId" name="warehouseCustomerId"  type="hidden" />
                <select  id="warehouseUserId" name="warehouseUserId" lay-filter="warehouseUserId" lay-verify="required" lay-search required></select>
            </div>
<!--            <div class="layui-input-block">-->
<!--                <input type="hidden" id="warehouseUserId" name="warehouseUserId" />-->
<!--                <select id="userNameId" name="userNameId" lay-filter="userNameId" lay-verify="required"  >-->
<!--                </select>-->
<!--            </div>-->
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">我方签约人</label>
            <div class="layui-input-block">
                <select  id="contractorId" name="contractorId" lay-filter="contractorId" lay-verify="required" lay-search required></select>
            </div>
        </div>
        <!--        <div class="layui-form-item">-->
        <!--            <label class="layui-form-label">备注信息</label>-->
        <!--            <div class="layui-input-block">-->
        <!--                <input id="remark" name="remark" placeholder="请输入备注信息" type="text" class="layui-input" autocomplete="off"/>-->
        <!--            </div>-->
        <!--        </div>-->
        <div class="layui-form-item">
            <label class="layui-form-label">上传附件</label>
            <div class="layui-input-block">
                <div id="contractFileUrlPath" class="companyFormPhotos"></div>
                <div id="btnContractFileUrl" class="layui-btn" style="float: left;"><i class="layui-icon">&#xe681;</i>上传PDF文件</div>
                <input  id="contractFileUrl" name="contractFileUrl" type="hidden" class="layui-input" lay-verify=""/>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">信息审批人</label>
            <div class="layui-input-block">
                <select  id="approverId" name="approverId" lay-filter="approverId" lay-verify="required" lay-search required></select>
            </div>
        </div>
        <div class="layui-form-item text-right">
            <button class="layui-btn layui-btn-primary" type="button" ew-event="closeDialog">取消</button>
            <button class="layui-btn" lay-filter="warehouseContractFormSubmit" lay-submit>保存</button>
        </div>
    </form>
</script>

<!--关联托管订单窗口-->
<script type="text/html" id="orderCodeSku" style="height: 400px">
    <div class="open-form">
        <div class="open-model">
            <div class="open-auto">
                <button class="layui-btn " id="addorderCodeSku">确认选择</button>
                <!-- 头部操作栏 -->
                <div class="layui-form" id="layuiFormSearch" style="margin-top: 20px;">
                    <div class="toolbar">
                        <div class="layui-form-item ">
                            <div class="lay-query-box">
                                <div class="query-lt" >
                                    <div class="layui-inline">
                                        <div class="layui-input-inline mr0">
                                            <input name="customerName" class="layui-input" type="text"
                                                   placeholder="请输入供应商名称"/>
                                        </div>
                                    </div>
                                    <div class="layui-inline">
                                        <div class="layui-input-inline mr0">
                                            <input name="customerCode" class="layui-input" type="text"
                                                   placeholder="请输入供应商编号"/>
                                        </div>
                                    </div>
                                    <div class="layui-inline">
                                        <div class="layui-input-inline">
                                            <input type="text" class="layui-input" id="storeTime" name="createTime" placeholder="请选择创建时间" readonly >
                                        </div>
                                    </div>
                                </div>
                                <div class="query-rt">
                                    <div class="layui-inline">
                                        <button class="layui-btn icon-btn color-green" lay-filter="itemSubSearchLog"
                                                lay-submit layui-form-keyDownSearch="true">查询
                                        </button>
                                        <button class="layui-btn icon-btn color-white" lay-filter="itemResets"
                                                lay-submit>重置
                                        </button>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>

                </div>
                <table class="layui-table" id="orderCodeSkuTable"></table>
            </div>
        </div>
    </div>
</script>


<script type="text/html" id="settledDetailContent">
    <form lay-filter="settledDetailContentForm" id="settledDetailContentForm" class="layui-form open-form">
        <div class="open-model">
            <div class="open-auto">
                <table class="layui-table" id="lookDataForm" lay-filter="lookDataForm"></table>
                <div class="layui-form-item layui-row" id="continto">
                    <div style="width: calc(50% - 25px);float:left;">
                        <label class="layui-form-label" style="text-align: left;width: auto;">服务产品价格：</label>
                        <table class="layui-table" id="serviceProductsFormTable"
                               lay-filter="serviceProductsFormTable"></table>
                    </div>
                    <div style="margin-left: 50px;float: right;width: calc(50% - 25px);">
                        <label class="layui-form-label" style="text-align: left;width: auto;">托管费用设置：</label>
                        <table class="layui-table" id="custodyFeesFormTable"
                               lay-filter="custodyFeesFormTable"></table>
                    </div>
                </div>
            </div>
        </div>
    </form>
</script>

<!-- js部分 -->
<script>
    layui.use(['layer', 'form', 'table', 'admin','upload','tableTreeDj','config','laydate'], function () {
        var $ = layui.jquery;
        var layer = layui.layer;
        var form = layui.form;
        var table = layui.table;
        var config = layui.config;
        var admin = layui.admin;
        var upload = layui.upload;
        var laydate = layui.laydate;
        var tableTree = layui.tableTreeDj;

        // 渲染表格
        var insTb = table.render({
            elem: '#warehouseContractTable',
            url: config.base + 'warehouse/warehouse/contract/list?type=1',
            toolbar: true,
            defaultToolbar: ["filter"],
            page: true,
            cellMinWidth: 100,
            cols: [[
                {type: 'numbers', title: '序号', fixed: 'left'}
                // ,{field: 'contractCode', title: '合同流水号', align: 'center'}
                ,{field: 'contractCode', title: '合同编号', align: 'center'}
                // ,{field: 'type',title: '合同类型', align: 'center'}
                ,{field: 'typeName',title: '合同类型', align: 'center'}
                ,{field: 'contractName', title: '合同名称', align: 'center'}
                // ,{field: 'orderCode', title: '所属订单' , align: 'center'}
                ,{field: 'customerName', title: '所属客户企业' , align: 'center'}
                ,{field: 'contractPrice', title: '合同金额' , align: 'center',
                    templet: function (d) {
                        if(d.contractPrice===''){
                            return 0
                        }else{
                            return d.contractPrice
                        }
                    },}
                ,{field: 'contactName', title: '联系人' , align: 'center'}
                // ,{field: 'status', title: '状态' , align: 'center'}
                // ,{field: 'warehouseUserPhone', title: '联系电话' , align: 'center'}
                ,{field: 'effectiveDate', title: '确认时间' , align: 'center'}
                ,{field: 'createTime', title: '上传时间' , align: 'center'}
                ,{align: 'center', toolbar: '#warehouseContractTableBar', title: '操作', width: 200, fixed: 'right'}
            ]],
            done: function (res, curr, count) {
                //移除按钮
                // var menuButton = config.getMenuButton(location.hash);
                // if(menuButton.indexOf("搜索") == -1){
                //     $('.layui-form.toolbar').remove();
                // }
                // if(menuButton.indexOf("修改") == -1){
                //     $("[lay-event='edit']").remove();
                // }
                // if(menuButton.indexOf("删除") == -1){
                //     $("[lay-event='del']").remove();
                // }
            }
        });

        // 工具条点击事件
        table.on('tool(warehouseContractTable)', function (obj) {
            var data = obj.data;
            if (obj.event === 'edit') { //修改
                showEditModel(data);
            } else if (obj.event === 'del') { // 删除
                doDelete(obj);
            }else if(obj.event ==='info'){
                admin.req(
                    "warehouse/warehouse/contract/info",
                    {id: data.id},
                    (res) => {
                        if (res.code === 200) {
                            let dataCont={...data,...res.data}
                            showEditModelImg(dataCont);
                        }
                    }
                );

            }
        });

        //监听排序
        table.on('sort(warehouseContractTable)', function(obj){
            table.reload('warehouseContractTable', {
                initSort: obj
                ,where: {
                    sort: obj.field
                    ,order: obj.type
                }
            });
        });

        // 搜索
        form.on('submit(formSubSearchLog)', function (data) {
            insTb.reload({where: data.field,page: {curr: 1}},'data');
        });

        // 重置搜索
        form.on('submit(resets)', function (data) {
            insTb.reload({where: admin.resetSearch(data.field), page: {curr: 1}}, 'data');
        });

        // 添加按钮点击事件
        $('#warehouseContractBtnAdd').click(function () {
            showEditModel();
        });
        var contractNameCS=''
        var contractNameOC=''
        var contractNameCC=''
        var getcontractName= function (){
            return $("#contractName").val(contractNameCC+contractNameOC+contractNameCS)
        }
        /*显示详情接口*/
        function showEditModelImg(data){
            admin.open({
                type: 1,
                area: ['80%', '800px'],
                offset: "10%",
                title: '详情',
                content: $('#settledDetailContent').html(),
                success: function () {
                    form.val('settledDetailContentForm', data);
                    data.contractCategory="托管合同"
                    let createProductionPlanTb = table.render({
                        elem: '#lookDataForm',
                        data: [data],
                        page: false,
                        cols: [[
                            {field: 'contractCode', align: 'center',title: '合同编号 '}
                            , {field: 'contractCategory', align: 'center', title: '合同类型'}
                            , {field: 'contractName', align: 'center', title: '合同名称'}
                            , {field: 'settledOrder', align: 'center', title: '所属订单'}
                            , {field: 'customerName', align: 'center', title: '所属客户企业'}
                            , {field: 'contractPrice', align: 'center', title: '合同金额'}
                            , {field: 'contactName', align: 'center', title: '联系人'}
                            , {field: 'telephone', align: 'center', title: '联系电话'}
                            , {field: 'effectiveDate', align: 'center', title: '签订时间'}
                            , {field: 'createTime', align: 'center', title: '上传时间'}
                        ]]
                    });

                    /*服务产品价格*/
                    let tableVal = table.render({
                        elem: "#serviceProductsFormTable",
                        limit: 9999,
                        height: 350,
                        data: [],
                        cols: [
                            [
                                {field: "feeItemName", align: "center", title: "业务项目"},
                                {field: "remark", align: "center", title: "业务描述"},
                                {field: "price", align: "center", title: "标准价"},
                                {field: "memberPrice", align: "center", title: "会员价"},
                                {
                                    field: "contractPrice", align: "center", title: "合同价格",
                                },
                            ]
                        ],
                        done: function (res, curr, count) {
                        },
                        parseData: function (res) {
                        },
                    });

                    /*托管费用设置*/
                    const VarietyVal = table.render({
                        elem: "#custodyFeesFormTable",
                        page: false,
                        limit: 9999,
                        height: 350,
                        data: [],
                        cols: [
                            [
                                {field: "varietyName", align: "center", title: "业务项目"},
                                {field: "warehouseContractPrice", align: "center", title: "标准价"},
                                {field: "memberPrice", align: "center", title: "会员价"},
                                {
                                    field: "contractPrice", align: "center", title: "合同价格",
                                },
                            ]
                        ],
                        done: function () {
                        },
                        parseData: function (res) {

                        },
                    });

                    if (data.warehouseContractFeeVOList != undefined) {
                        tableVal.reload({
                            data: data.warehouseContractFeeVOList.map(v => {
                                delete v.length
                                return v
                            }),
                        });
                    }
                    if (data.warehouseContractProductVOList != undefined) {
                        VarietyVal.reload({
                            data: data.warehouseContractProductVOList.map(v => {
                                delete v.length
                                return v
                            })
                        });
                    }

                }
            })
        }
        // 显示编辑弹窗
        function showEditModel(data) {
            admin.open({
                type: 1,
                area: '640px',
                offset: '65px',
                title: data ? '修改合同' : '添加合同',
                content: $('#warehouseContractForm').html(),
                success: function () {
                    // 查看大图
                    layer.photos({
                        photos: '.companyFormPhotos'
                        ,anim: 5
                    });
                    //客户信息

                    admin.reqSync('enterprise/sell/admin/customersInfo/list', {'limit':9999}, function (res) {
                        layer.closeAll('loading');
                        if (res.code == 200) {
                            loadSelectHtml(res.data, "请选客户信息", "customerNameId",4);
                        }
                    }, 'GET');
                    //合同分类

                    admin.reqSync('enterprise/contract/admin/contractCategory/list?page=1&limit=9999', {}, function (res) {
                        layer.closeAll('loading');
                        if (res.code == 200) {
                            loadSelectHtml(res.data, "请选择合同分类", "contractCategoryId");
                        }
                    }, 'GET');

                    var warehouseCustomerId
                    form.on('select(customerNameId)', function (data) {
                        $("#orderCode").val('')
                        if (data.value === '') {
                        } else {
                            console.log(data.elem[data.elem.selectedIndex].text,"data")
                            contractNameCS=data.elem[data.elem.selectedIndex].text

                            //关联托管订单
                            // debugger;
                            warehouseCustomerId=data.value;
                            getcontractName()
                            let dataObj = JSON.parse($(data.elem[data.elem.selectedIndex]).attr('data'));
                            $("#customerId").val(dataObj.id)
                            userNameSelect(dataObj)
                            // admin.reqSync('warehouse/warehouse/order/findListByCustomerId?page=1&limit=9999&warehouseCustomerId='+warehouseCustomerId, {}, function (res) {
                            //     layer.closeAll('loading');
                            //     if (res.code == 200) {
                            //         // loadSelectHtml(res.data, "请选择关联托管订单", "orderCode",1);
                            //     }
                            // }, 'GET');
                        }
                    });
                    //if(data){

                        //关联托管订单
                        // admin.reqSync('warehouse/warehouse/order/findListByCustomerId?page=1&limit=9999&warehouseCustomerId='+data.warehouseCustomerId, {}, function (res) {
                        //     layer.closeAll('loading');
                        //     if (res.code == 200) {
                        //         // loadSelectHtml(res.data, "请选择关联托管订单", "orderCode",1);
                        //     }
                        // }, 'GET');
                    //}

                    form.on('select(contractCategoryId)', function (data) {
                        if (data.value === '') {
                        } else {
                            contractNameCC=data.elem[data.elem.selectedIndex].text
                            getcontractName()
                        }
                    })
                    /*关联托管订单点击窗口*/
                    $("#orderCode").click(function () {
                        if(!warehouseCustomerId){layer.msg("请先选择所属客户", {icon: 2}); return}
                        let newindex = admin.formOpen({
                            area: "90%",
                            offset: "2%",
                            title: "选择关联托管订单",
                            content: $("#orderCodeSku").html(),
                            success: function () {
                                skuTable = table.render({
                                    elem: "#orderCodeSkuTable",
                                    url: config.base + 'warehouse/warehouse/order/list',
                                    where: {
                                        warehouseCustomerId:warehouseCustomerId,
                                        orderCode:'',
                                        page:1,
                                        limit:9999,
                                        notIds: []
                                    },
                                    page: false,
                                    height: 650,
                                    cols: [
                                        [
                                            {type: "radio"}
                                            ,{field: 'orderCode', title: '订单编号', align: 'center'}
                                            ,{field: 'sourceDesc',title: '数据来源', align: 'center'}
                                            // ,{field: 'totalQuantity', title: '物料数量', align: 'center'}
                                            ,{field: 'rowsd', title: '物料数量', align: 'center'}
                                            // ,{field: 'customerId', title: '客户代码' , align: 'center'}
                                            ,{field: 'code', title: '客户代码' , align: 'center'}
                                            ,{field: 'warehouseUser', title: '联系人' , align: 'center'}
                                            // ,{field: 'totalPrice', title: '托管单价' , align: 'center'}
                                            ,{field: 'totalWeight', title: '订单物料重量' , align: 'center'}
                                            ,{field: 'storeTime', title: '计划入库时间' , align: 'center'}
                                            ,{field: 'chargingTime', title: '计划计费时间' , align: 'center'}
                                            ,{field: 'status', title: '状态' , align: 'center',
                                            templet: function (d) {
                                                // 根据 status 的值返回对应的显示内容 0已撤销1.待受理2.已受理3.待发货4.已发货5.签收完成6.入库完成
                                                switch (d.status) {
                                                    case 0:
                                                        return '<span style="color: #999;">已撤销</span>'; // 灰色
                                                    case 1:
                                                        return '<span style="color: #999;">待受理</span>'; // 灰色
                                                    case 2:
                                                        return '<span style="color: #5FB878;">已受理</span>'; // 绿色
                                                    case 3:
                                                        return '<span style="color: #FF5722;">待发货</span>';
                                                    case 4:
                                                        return '<span style="color: #FF5722;">已发货</span>';
                                                    case 5:
                                                        return '<span style="color: #FF5722;">签收完成</span>'; // 红色
                                                    case 6:
                                                        return '<span style="color: #FF5722;">入库完成</span>'; // 红色
                                                    default:
                                                        return '未知状态';
                                                }
                                            }}
                                            ,{field: 'createTime', title: '创建时间' , align: 'center'}
                                            // ,{field: 'creator', title: '创建人' , align: 'center'}
                                            ,{field: 'nickname', title: '创建人' , align: 'center'}
                                        ]
                                    ]
                                });
                                $("#addorderCodeSku").click(  function () {
                                    let checkData = table.checkStatus("orderCodeSkuTable").data;
                                    checkData = checkData.map((v) => {
                                        v.productId = v.id;
                                        return v;
                                    });
                                    // console.log(checkData,"checkData")
                                    $("#warehouseCustomerId").val(checkData[0].customerId)
                                    $("#orderCode").val(checkData[0].orderCode)
                                    contractNameOC=checkData[0].orderCode
                                    getcontractName()
                                    layer.close(newindex);
                                });

                                laydate.render({
                                    elem: '#storeTime',
                                    format: 'yyyy-MM-dd'
                                });

                                // 搜索
                                form.on("submit(itemSubSearchLog)", function (data) {
                                    console.log(data,"asaio")
                                    skuTable.reload({
                                        where: {
                                            ...data.field
                                        },
                                        page: {curr: 1}
                                    }, "data")
                                });

                                // 重置搜索
                                form.on("submit(itemResets)", function (data) {
                                    skuTable.reload({
                                        where: {
                                            ...admin.resetSearch(data.field),
                                            notIds:  []
                                        },
                                        page: {curr: 1}
                                    });
                                });
                            }
                        });
                    });

                    form.on('select(orderCode)', function (data) {
                        if (data.value === '') {
                        } else {
                            let dataObj = JSON.parse($(data.elem[data.elem.selectedIndex]).attr('data'));
                            $("#warehouseCustomerId").val(dataObj.customerId)
                        }
                    });
                    //客户签约人

                    function userNameSelect(data) {
                        admin.reqSync('enterprise/sell/admin/contactInfo/list?page=1&limit=9999', {selCustomerId:data ? data.id:null}, function (res) {
                            // debugger;
                            layer.closeAll('loading');
                            if (res.code == 200) {
                                data.customerNameId=data.warehouseCustomerId;
                                data.customerName=data.warehouseCustomer;
                                loadSelectHtml(res.data, "请选客户信息", "warehouseUserId",3);
                            }
                        }, 'GET');
                    }


                    if(data){
                        warehouseCustomerId=data.warehouseCustomerId;
                        data.customerNameId=data.warehouseCustomerId;
                        data.customerName=data.warehouseCustomer;
                        userNameSelect(data.customerNameId);
                    }

                    // 我方签约人/信息审批人
                    admin.reqSync('user/admin/user/list', {limit: 9999}, function (res) {
                        layer.closeAll('loading');
                        if (res.code == 200) {
                            loadSelectHtml(res.data, "请选择我方签约人", "contractorId",2);
                            loadSelectHtml(res.data, "请选择信息审批人", "approverId",2);
                        }
                    }, 'GET');

                    form.val('warehouseContractForm', data);

                    $('#btnContractFileUrl').click(uploadImg('btnContractFileUrl','contractFileUrlPath','contractFileUrl'));

                    // 表单提交事件
                    form.on('submit(warehouseContractFormSubmit)', function (d) {
                        layer.load(2);
                        admin.req(data ? 'warehouse/warehouse/contract/update' : 'warehouse/warehouse/contract/add', d.field, function (res) {
                            layer.closeAll('loading');
                            if (res.code == 200) {
                                layer.msg(res.msg, {icon: 1});
                                table.reload('warehouseContractTable');
                                layer.closeAll('page');
                            } else {
                                layer.msg(res.msg, {icon: 2});
                            }
                        }, data ? 'PUT' : 'POST');
                        return false;
                    });
                }
            });
        }
        // option渲染
        function loadSelectHtml(data, tips, htmltarget, type) {
            let html = ' <option value>' + tips + '</option>';
            if (!data || data == null) {
                return;
            }
            for (let i = 0; i < data.length; i++) {
                if (type == 1) {
                    html += `<option value='${data[i].orderCode}' data='${JSON.stringify(data[i])}'>${data[i].orderCode}</option>`;
                } else if (type == 2){
                    html += `<option value='${data[i].id}' data='${JSON.stringify(data[i])}'>${data[i].nickname}</option>`;
                } else if(type==4){
                    html += `<option value='${data[i].id}' id='${data[i].id}' data='${JSON.stringify(data[i])}' >${data[i].customerName}</option>`;
                }
                else if (type == 3){
                    html += `<option value='${data[i].id}' id='${data[i].id}' data='${JSON.stringify(data[i])}'>${data[i].name}</option>`;
                } else  {
                    html += `<option value='${data[i].id}' data='${JSON.stringify(data[i])}'>${data[i].name}</option>`;
                }
            }

            $("form select[name='" + htmltarget + "']").html(html);
            form.render('select');
        }

        // 上传图片
        function uploadImg(_elem, pathId, inputId) {
            upload.render({
                elem: '#' + _elem
                , url: config.upload_url + 'uploadFile'
                , data: {}
                , accept: 'file'
                , exts: 'jpg|png|RAR|zip|pdf|txt|doc|docx|xls|xlsx|ppt|pptx'
                , headers: { Authorization: 'Bearer ' + config.getToken() }
                , done: function (res) {
                    if (res.code == 200) {
                        layer.msg(res.msg || "上传成功", { icon: 1 });
                        let imagUrl = res.data.url;
                        $('#' + pathId).html('<img src="' +imagUrl + '"/>');
                        $('#' + inputId).val(imagUrl);
                    } else if (res.code == 502) {
                        return location.replace('member/login.html');
                    } else {
                        layer.msg(res.msg || "上传失败", { icon: 2 });
                    }
                }
            });
        }
    });
</script>